<template>
	<view class="edit-phone">
		<view class="input-box">
			<view class="input-line">
				<view class="input-line-title fz16 mr10">
					设置密码
				</view>
				<u-input v-model="password" :clearable="false" placeholder='请输入密码' type="password" />
			</view>
			<view class="input-line">
				<view class="input-line-title fz16 mr10">
					确认密码
				</view>
				<u-input v-model="verify_password" :clearable="false" placeholder='请再次输入密码' type="password" />
			</view>
		</view>
		<view class="controls-btn-box zhong">
			<u-button class="controls-btn" @click="resetPassword" :throttle-time='2000'>保存</u-button>
		</view>
	</view>
</template>

<script>
	import {
		resetPassword,
	} from '@/network/loginAndMy.js'
	export default {
		data() {
			return {
				password: '', // 密码
				verify_password: '', // 确认密码
			}
		},
		computed: {

		},
		mounted() {

		},
		methods: {
			// 重置密码
			resetPassword() {
				if(this.contentVerify()) return
				let params = {
					type: 'other',
					mobile: uni.getStorageSync('phone'),
					newpassword: this.password,
					captcha: ""
				}
				resetPassword(params).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '重置成功',
							duration: 2000,
							icon: 'none',
							success: function(res) {
								setTimeout(()=>{
									uni.navigateBack({
										delta: 1
									});
								},2000)
							}
						});
					}
				})
			},
			// 输入内容验证
			contentVerify() {
				if (this.password == '') {
					uni.showToast({
						title: '请输入密码',
						duration: 2000,
						icon: 'none'
					});
					return true
				}
			
				// let regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,16}$/
				// if (!regex.test(this.password)) {
				// 	uni.showToast({
				// 		title: '用户密码长度必须介于 8 和 16 之间包含大写字母、小写字母、数字和特殊符号',
				// 		duration: 3000,
				// 		icon: 'none'
				// 	});
				// 	return true
				// }
			
				if (this.verify_password == '') {
					uni.showToast({
						title: '请输入确定密码',
						duration: 2000,
						icon: 'none'
					});
					return true
				}
			
				if (this.password !== this.verify_password) {
					uni.showToast({
						title: '两次输入密码不一致!',
						duration: 2000,
						icon: 'none'
					});
					return true
				}
			
				return false
			},
		},
	}
</script>

<style lang="scss">
	.edit-phone {
		background: #F3F3F3;
		height: 100vh;

		.input-box {
			padding: 0 30rpx;
			background-color: #ffffff;

			.input-line {
				height: 140rpx;
				width: 100%;
				box-sizing: border-box;
				border-bottom: 1rpx solid #EDEDED;

				.input-line-title {
					width: 100%;
					height: 70rpx;
					line-height: 70rpx;
				}

				.get-code-box {
					width: 150rpx;
					height: 44rpx;
					line-height: 44rpx;
					text-align: center;
					border: 1rpx solid #E3BA5B;
					border-radius: 5rpx;
					color: #BB8422;
					margin: 0 !important;
					padding: 0 !important;
					font-size: 24rpx;
				}

				uni-button:after {
					content: " ";
					border: none !important;
				}
			}
		}

		.controls-btn-box {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 140rpx;
			background-color: #ffffff;

			.controls-btn {
				border: none;
				margin: 0 !important;
				padding: 0 !important;
				font-size: 36rpx;
				color: #ffffff;
				background: linear-gradient(0deg, #b07412 0%, #e3ba5b 100%);
				border-radius: 10rpx;
				height: 90rpx;
				line-height: 90rpx;
				width: 690rpx;
			}

			uni-button:after {
				content: " ";
				border: none !important;
			}
		}
	}
</style>